import { Button, Space } from 'antd';
import { atom, useAtom } from 'jotai';

const num1Atom = atom(0);
const num2Atom = atom(1);

type TestType = {
	name: string;
	age: number;
};

const objAtom = atom({ name: null, age: null });

const App1 = () => {
	console.log('App11111');
	const [num1, setNum1] = useAtom(num1Atom);

	const [bar, setBar] = useAtom(objAtom);

	return (
		<Button type="primary" onClick={() => setNum1(num1 + 1)}>
			App1: {num1}
		</Button>
	);
};

const App2 = () => {
	console.log('App22222');
	const [num2, setNum2] = useAtom(num2Atom);

	return (
		<Button type="primary" onClick={() => setNum2(num2 + 1)}>
			App1: {num2}
		</Button>
	);
};

const ReRender = () => {
	return (
		<Space>
			<App1 />
			<App2 />
		</Space>
	);
};

export default ReRender;
